package com.formula.datastructure.exercise.tree;

/**
 * 顺序的遍历在tree里面
 */
public class BinarySqTree {
    private BinarySqNode[] array;

    private int size;

    public BinarySqTree() {
        array = new BinarySqNode[50];
        size = 0;
    }

    public void inOrder() {
        if (size > 0) {
            inOrderNode(0);
        }
    }

    public void inOrderNode(int idx) {
        if (array[array[idx].left] != null) {
            visit(array[array[idx].left]);
        }
        visit(array[idx]);
        if (array[array[idx].right] != null) {
            visit(array[array[idx].right]);
        }
    }

    private void visit(BinarySqNode node) {
        System.out.println(node.data);
    }

}
